#include <iostream>
#include <string>
#include <fstream>
#include "bundle.h"
using namespace std;

int main(int argc, char* argv[])
{
    if(argc < 3)
    {
        cout << "请输入需要解压的目标文件名及解压后的文件名" << endl;
        return -1;
    }

    string target_filename = argv[1];
    string unpack_filename = argv[2];
    // 读取解压的目标文件
    ifstream ifs;
    ifs.open(target_filename, ios_base::binary);
    ifs.seekg(0, ios_base::end);
    size_t fsize = ifs.tellg();
    ifs.seekg(0, ios_base::beg);
    string body;
    body.resize(fsize);
    ifs.read(&body[0], fsize);
    // 解压目标文件
    string unpack = bundle::unpack(body);
    // 将解压后的数据放入文件中
    ofstream ofs;
    ofs.open(unpack_filename, ios_base::binary);
    ofs.write(&unpack[0], unpack.size());

    ifs.close();
    ofs.close();

    return 0;
}